home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1985 June / Ahoy_Magazine_85-06_1985_Double_L.d64 / 3 voice player (.txt) next >
Commodore BASIC  |  2022-10-26  |  6KB  |  201 lines

  1. 1 rem "three voice player"
  2. 2 rem play 1, 2, or 3 voices with this routine
  3. 3 rem add it to your programs: adjust the durations at 9200-9210 as needed
  4. 4 rem
  5. 5 rem plays "god save the king" ("my country, 'tis of thee")
  6. 6 rem
  7. 7 print"[147]":poke53280,0:poke53281,6
  8. 8 print:printtab(10)"three voice player"
  9. 9 print:printtab(10)"god save the king"
  10. 10 gosub 9000:goto 120
  11. 60 for n=1 to len(md$(ph))
  12. 61 for vc=0 to ev%
  13. 62 poke gr(vc),ug%(vc):rem normal notes; don't poke ug% for legato
  14. 63 for i=0 to 1
  15. 64 poke fr(vc,i),pi%(asc(mid$(me$(ph,vc),n,1)),i)
  16. 65 next:next
  17. 66 for vc=ev% to 0 step -1:poke gr(vc),g%(vc):next
  18. 67 for i=0 to du%(val(mid$(md$(ph),n,1))):next
  19. 68 rem for vc=0 to ev%:poke gr(vc),ug%(vc):next:rem staccato notes
  20. 69 next:ph=ph+1:if ph>es% then ph=0
  21. 70 for vc=0 to ev%:poke gr(vc),ug%(vc):next:return
  22. 100 gosub 60
  23. 110 if peek(653)>0 then end
  24. 120 print "phrase "ph
  25. 190 goto 100
  26. 8997 rem
  27. 8998 rem set up sound shape
  28. 8999 rem
  29. 9000 dim md$(23),me$(23,2),mv$(23,2),g%(2),gr(2),fr(2,1),ad(2)
  30. 9001 dim du%(9),pi%(168,1),ak%(2),dy%(2),sn%(2),re%(2),wf%(2)
  31. 9007 rem
  32. 9008 rem attack--voices 0,1,2
  33. 9009 rem number from 0 to 15; lower number=sharper attack
  34. 9010 ak%(0)=2:ak%(1)=2:ak%(2)=2
  35. 9015 for i=0 to 2:ak%(i)=ak%(i)*16:next
  36. 9017 rem
  37. 9018 rem decay--voices 0,1,2
  38. 9019 rem number from 0 to 15; lower number=faster decline
  39. 9020 dy%(0)=4:dy%(1)=6:dy%(2)=6
  40. 9027 rem
  41. 9028 rem sustain--voices 0,1,2
  42. 9029 rem number from 0 to 15; lower number=softer volume during sustain
  43. 9030 sn%(0)=12:sn%(1)=8:sn%(2)=9
  44. 9035 for i=0 to 2:sn%(i)=sn%(i)*16:next
  45. 9037 rem
  46. 9038 rem release--voices 0,1,2
  47. 9039 rem number from 0 to 15; lower number=faster drop to silence at end
  48. 9040 re%(0)=0:re%(1)=3:re%(2)=5
  49. 9047 rem
  50. 9048 rem set sound addresses
  51. 9049 rem
  52. 9050 fr(0,0)=54272:fr(1,0)=54279:fr(2,0)=54286
  53. 9055 for i=0 to 2:fr(i,1)=1+fr(i,0):gr(i)=fr(i,0)+4:ad(i)=gr(i)+1:next
  54. 9057 rem
  55. 9058 rem poke adsr envelopes
  56. 9059 rem
  57. 9060 for i=0 to 2:poke ad(i),at%(i) or dy%(i)
  58. 9065 poke ad(i)+1,sn%(i) or re%(i):next
  59. 9066 rem
  60. 9067 rem set up gates
  61. 9068 rem waveforms, voices 0,1,2 (add values):
  62. 9069 rem triangle on=16; sawtooth on=32; pulse on=64 (set width!); noise on=128
  63. 9070 wf%(0)=64:wf%(1)=64:wf%(2)=32
  64. 9075 for i=0 to 2:g%(i)=1 or wf%(i):ug%(i)=g%(i)and 254:next
  65. 9077 rem
  66. 9078 rem set pulse widths
  67. 9079 rem voices 0,1,2; low byte, high byte
  68. 9080 poke gr(0)-2,200:poke gr(0)-1,3
  69. 9081 poke gr(1)-2,200:poke gr(1)-1,3
  70. 9082 poke gr(2)-2,200:poke gr(2)-1,3
  71. 9096 rem
  72. 9097 rem set up pitch array
  73. 9098 rem each note, in all its octaves
  74. 9099 rem c
  75. 9100 x%=3:gosub 9190
  76. 9101 data 12,1,24,2,48,4,97,8,195,16,135,33,15,67,30,134
  77. 9102 rem d
  78. 9103 x%=4:gosub 9190
  79. 9104 data 45,1,90,2,180,4,104,9,209,18,162,37,69,75,139,150
  80. 9105 rem e (f-flat)
  81. 9106 x%=5:gosub 9190:y%=13:gosub 9195
  82. 9107 data 81,1,163,2,71,5,143,10,31,21,62,42,125,84,250,168
  83. 9108 rem f (e-sharp)
  84. 9109 x%=6:gosub 9190:y%=19:gosub 9195
  85. 9110 data 102,1,204,2,152,5,48,11,96,22,193,44,131,89,6,179
  86. 9111 rem g
  87. 9112 x%=7:gosub 9190
  88. 9113 data 145,1,35,3,71,6,143,12,30,25,60,50,121,100,243,200
  89. 9114 rem a
  90. 9115 x%=1:gosub 9190
  91. 9116 data 195,1,134,3,12,7,24,14,49,28,99,56,199,112,143,225
  92. 9117 rem b
  93. 9118 x%=2:gosub 9190
  94. 9119 data 250,1,244,3,233,7,210,15,165,31,75,63,151,126,46,253
  95. 9120 rem d-flat (c-sharp)
  96. 9121 x%=11:gosub 9190:y%=17:gosub 9195
  97. 9122 data 28,1,56,2,112,4,225,8,195,17,134,35,12,71,24,142
  98. 9123 rem e-flat (d-sharp)
  99. 9124 x%=12:gosub 9190:y%=18:gosub 9195
  100. 9125 data 62,1,125,2,251,4,247,9,239,19,223,39,191,79,126,159
  101. 9126 rem g-flat (f-sharp)
  102. 9127 x%=14:gosub 9190:y%=20:gosub 9195
  103. 9128 data 123,1,246,2,237,5,218,11,181,23,107,47,214,94,172,189
  104. 9129 rem a-flat (g-sharp)
  105. 9130 x%=8:gosub 9190:y%=21:gosub 9195
  106. 9131 data 169,1,83,3,167,6,78,13,156,26,57,53,115,106,230,212
  107. 9132 rem b-flat (a-sharp)
  108. 9133 x%=9:gosub 9190:y%=15:gosub 9195
  109. 9134 data 221,1,187,3,119,7,239,14,223,29,190,59,124,119,248,238
  110. 9135 rem c-flat
  111. 9136 x%=10:gosub 9190
  112. 9137 data 4,1,250,1,244,3,233,7,210,15,165,31,75,63,151,126
  113. 9138 rem b-sharp
  114. 9139 x%=16:gosub 9190
  115. 9140 data 24,2,48,4,97,8,195,16,135,33,15,67,30,134,255,255
  116. 9185 goto 9200
  117. 9189 rem read pitches
  118. 9190 for i=0 to 147 step 21:read pi%(i+x%,0),pi%(i+x%,1):next:return
  119. 9194 rem identical pitches
  120. 9195 for i=0 to 147 step 21:pi%(i+y%,0)=pi%(i+x%,0):pi%(i+y%,1)=pi%(i+x%,1)
  121. 9196 next:return
  122. 9197 rem
  123. 9198 rem set up durations
  124. 9199 rem
  125. 9200 for i=0 to 9:read du%(i):next
  126. 9205 data 0,128,256,384,512,640,768,1024,1152,1280
  127. 9296 rem
  128. 9297 rem set filter and volume
  129. 9298 rem filter frequency
  130. 9299 rem low byte (0-7) x%; high byte (0-255) y%
  131. 9300 x%=0:y%=100
  132. 9305 poke 54293,x%:poke 54294,y%
  133. 9308 rem filter on?
  134. 9309 rem voice 1 on=1; 2 on=2; 3 on=4; 1&2 on=3; 2&3 on=6; all on=7
  135. 9310 x%=0
  136. 9318 rem filter resonance
  137. 9319 rem peak volume (0=low, 15=high)
  138. 9320 y%=14
  139. 9325 y%=y%*16:poke 54295,x% or y%
  140. 9328 rem select filter type
  141. 9329 rem low-pass=1;band-pass=2;high-pass=4;lo-band=3;hi-band=6;all=7
  142. 9330 x%=1
  143. 9335 x%=x%*16
  144. 9337 rem
  145. 9338 rem select overall volume
  146. 9339 rem 15=high, 0=low
  147. 9340 y%=15
  148. 9345 poke 54296,x% or y%
  149. 9496 rem
  150. 9497 rem set melodies here
  151. 9498 rem
  152. 9499 rem how many voices? (minus one)
  153. 9500 ev%=2
  154. 9508 rem
  155. 9509 rem how many phrases? (minus one)
  156. 9510 es%=1
  157. 9514 rem
  158. 9515 rem melody strings
  159. 9516 rem
  160. 9517 rem each phrase has only one du%(ph) string, no matter how many voices
  161. 9518 rem each phrase has one me$(ph,vc) & one mv$(ph,vc) string per voice
  162. 9519 rem phrase 0
  163. 9520 md$(0)="2224022224022228"
  164. 9521 me$(0,0)="ffgefgaa[191]agfgfef"
  165. 9522 mv$(0,0)="5               "
  166. 9523 me$(0,1)="ccdcdecfgfeadagc"
  167. 9524 mv$(0,1)="5            4 5"
  168. 9525 me$(0,2)="fa[191]cccfd[191]ccd[191]cca"
  169. 9526 mv$(0,2)="3  234  34  343 "
  170. 9529 rem phrase 1
  171. 9530 md$(1)="2224022224022000040200228"
  172. 9531 me$(1,0)="cccc[191]a[191][191][191][191]aga[191]agfa[191]cd[191]agf"
  173. 9532 mv$(1,0)="6   5              6 5   "
  174. 9533 me$(1,1)="aaaagfggggfeff@f@feffgfea"
  175. 9534 mv$(1,1)="43 4   3 4   3   4      3"
  176. 9535 me$(1,2)="facfffcegcbcfdc[191]acga[191]dccf"
  177. 9536 mv$(1,2)="2 32      1234 3  2  3 21"
  178. 9897 rem
  179. 9898 rem convert strings to usable form
  180. 9899 rem
  181. 9900 for ph=0 to es%:for vc=0 to ev%
  182. 9905 a$=me$(ph,vc):me$(ph,vc)=""
  183. 9910 for i=1 to len(a$)
  184. 9920 x%=asc(mid$(a$,i,1))
  185. 9930 if x%<72 then x%=x%-64:if x%<0 then x%=0
  186. 9931 if x%>192and x%<200 then x%=x%-178
  187. 9932 if x%=176 then x%=8
  188. 9933 if x%=191 then x%=9
  189. 9934 if x%=188 then x%=10
  190. 9935 if x%=172 then x%=11
  191. 9936 if x%=177 then x%=12
  192. 9937 if x%=187 then x%=13
  193. 9938 if x%=165 then x%=14
  194. 9939 if x%>21 then x%=0
  195. 9950 v$=mid$(mv$(ph,vc),i,1):if v$<>" " then y%=21*val(v$)
  196. 9960 x%=x%+y%
  197. 9970 me$(ph,vc)=me$(ph,vc)+chr$(x%)
  198. 9975 next:next:next
  199. 9980 ph=0
  200. 9990 return
  201.